# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=cilium-cli
pkgver=0.15.11
pkgrel=1
pkgdesc="install, manage & troubleshoot Kubernetes clusters running Cilium"
arch=("loong64" "x86_64")
url="https://github.com/cilium/cilium-cli"
license=("APACHE")
depends=("glibc")
makedepends=("go")
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('4c0021ae152d4ffa107daa30d9828122a8670cfdf95a4a059cc4771dd34e2b2b')

build() {
	cd "$pkgname-$pkgver"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOPATH="${srcdir}"
	export GOFLAGS="-buildmode=pie -mod=vendor -modcacherw"
	go build \
		-ldflags "-compressdwarf=false -linkmode external -X \"github.com/cilium/cilium-cli/internal/cli/cmd.Version=v${pkgver}\"" \
		-o ${pkgname} ./cmd/cilium
}

package() {
	cd "$pkgname-$pkgver"
	install -Dm755 ${pkgname} -t "$pkgdir/usr/bin"

	./cilium-cli completion bash | install -Dm644 /dev/stdin "$pkgdir/usr/share/bash-completion/completions/cilium-cli"
	./cilium-cli completion zsh | install -Dm644 /dev/stdin "$pkgdir/usr/share/zsh/site-functions/_cilium-cli"
	./cilium-cli completion fish | install -Dm644 /dev/stdin "$pkgdir/usr/share/fish/vendor_completions.d/cilium-cli.fish"
}
